<?php
/*
 * 发号机相关程序
 * yifan5
 * 
 * 发号表为mipiao_numbermachine
 * 号表哈希成10张表，mipiao_number0~9.这只是初期考虑，
 * 如果数据量非常大了，就要重新调整哈希结构了。
 */

/*
 * 发号
 */
function createPiao($count,$shopuid="0",$activityuid="0",$denomination="0"){
	global $MIPIAO;
	$sql_select="select number from {$MIPIAO}numbermachine ";
	$query=mysql_query($sql_select);
	$res = mysql_fetch_array($query);
	$number = $res['number'];//当前米票号
	
	$sql_update = "UPDATE {$MIPIAO}numbermachine SET number=number+{$count}";
	mysql_query($sql_update);
	
	$time = time();
	$limit = $number+$count;
	for($number;$number<=$limit;$number++){
		$i = substr($number,-1);
		$sql_insert = "INSERT INTO {$MIPIAO}number{$i} (`number`,`shopuid`,`activityuid`,`createtime`,`denomination`,`status`)
		VALUES  ('{$number}','{$shopuid}','{$activityuid}','{$time}','{$denomination}','0')";
		mysql_query($sql_insert);
	}
} 